package _9994FuWuDingWeiQo;

/**
 * @ServiceLocator: 服务定位器
 * @author: ZBoHang
 * @time: 2021/9/18 12:02
 */
public class ServiceLocator {
    private static final Cache cache ;

    static {
        cache = new Cache();
    }

    public static Service getService(String jndiName) {
        Service service = cache.getService(jndiName);

        if (service != null) {
            return service;
        }
        InitialContext context = new InitialContext();
        Service newService = (Service) context.lookUp(jndiName);
        cache.addService(newService);
        return newService;
    }
}
